home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
pas_0493.zip
/
MUSIC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-04-23
|
5KB
|
147 lines
─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 588 of 702
From : Bill Buchanan 1:2410/225.0 19 Apr 93 11:48
To : Robert Macdonald
Subj : Music
────────────────────────────────────────────────────────────────────────────────
-=> Quoting Robert Macdonald to All <=-
RM> I'm just learning Pascal, and I was 1dering if it's possible 2 play
RM> music in Pascal? If so... how?
RM> C U L8r!
Here's a little program that allows you to play the "PIANO" on your keyboard.
No soundcard needed or anything like that. This may give you a small idea
on how to create your own sounds ...
Program Music; {by Judy Birmingham, 9/18/92}
Uses Crt;
Const
{-------------------------------------------------------------------}
{These values will vary by the song you choose}
{I wish I could have made these variables instead of constants,
but I seemed to be locked into using const, because they define
array sizes in the types declared below.}
TotalLinesInSong = 4; {Number of lines in song}
MaxNotesInPhrase = 9; {Max number of notes in any line}
BeatNote = 4; {Bottom number in Time Signature}
{Handles cut time (2/2), 6/8 etc.}
Tempo = 160; {Number of beats per minute}
{-------------------------------------------------------------------}
{Note frequencies}
R = 0; {Rest = frequency of 0 : silence}
C = 260; {Frequency of middle c }
CC = 277; {Double letter indicates a sharp}
D = 294;
DD = 311;
E = 330;
F = 349;
FF = 370;
G = 392;
GG = 415;
A = 440;
AA = 466;
B = 494;
{Note durations}
Q = 1 * (BeatNote/4); {Quarter note}
I = 0.5 * (BeatNote/4); {Eighth note}
H = 2 * (BeatNote/4); {Half note}
W = 4 * (BeatNote/4); {Whole note}
S = 0.25 * (BeatNote/4); {Sixteenth note}
DQ = 1.5 * (BeatNote/4); {Dotted quarter}
DI = 0.75 * (BeatNote/4); {Dotted eighth}
DH = 3 * (BeatNote/4); {Dotted half}
DS = 0.375 * (BeatNote/4); {Dotted sixteenth}
Beat = 60000/Tempo; {Duration of 1 beat in millisecs}
Type IValues = Array [1..MaxNotesInPhrase] of Integer;
RValues = Array [1..MaxNotesInPhrase] of Real;
Phrase = Record
Lyric : String;
Notes : IValues; {array of note frequencies}
Octave : IValues; {array of note octaves}
Rhythm : RValues; {array of note durations}
end;
Song = Array [1..TotalLinesInSong] of Phrase;
{Sample song}
CONST RowRow : Song =
(
(Lyric : 'Row Row Row Your Boat';
NOTES : (C,C,C,D,E,R,0,0,0);
OCTAVE : (1,1,1,1,1,1,0,0,0);
RHYTHM : (DQ,DQ,Q,I,Q,I,R,0,0)
),
(Lyric : 'Gently down the stream';
NOTES : (E,D,E,F,G,R,0,0,0);
OCTAVE : (1,1,1,1,1,1,0,0,0);
RHYTHM : (Q,I,Q,I,DQ,DQ,0,0,0)
),
(Lyric : 'Merrily merrily merrily merrily';
NOTES : (C,C,G,G,E,E,C,C,0 );
OCTAVE : (2,2,1,1,1,1,1,1,0 );
RHYTHM : (Q,I,Q,I,Q,I,Q,I,0 )
),
(Lyric : 'Life is but a dream.';
NOTES : (G,F,E,D,C,R,0,0,0 );
OCTAVE : (1,1,1,1,1,1,0,0,0 );
RHYTHM : (Q,I,Q,I,H,Q,0,0,0 )
));
Procedure LYRICS (THE_WORDS : string);
begin
Writeln (THE_WORDS);
end;
Procedure PLAYNOTE (NOTE, OCT: integer; DURATION : real);
begin
Sound (NOTE * OCT);
Delay (Round(BEAT * DURATION));
NoSound;
End;
Procedure PLAYPHRASE (N : integer; NOTES, OCTAVE : IValues; RHYTHM :
RValues) ;
Var INDEX : Integer;
Begin
For INDEX := 1 to N do
PLAYNOTE (NOTES[INDEX], OCTAVE[INDEX], RHYTHM[INDEX]);
End;
Procedure PLAYSONG (Title : String; Tune : Song);
Var Counter : Integer;
begin
ClrScr;
GotoXY(11,3);
Writeln (Title);
Window (10,5,70,19);
ClrScr;
For counter := 1 to TotalLinesInSong do
begin
LYRICS(Tune[counter].Lyric);
PLAYPHRASE(MaxNotesInPhrase,Tune[counter].Notes,
Tune[counter].Octave, Tune[counter].Rhythm);
end;
end;
BEGIN
ClrScr;
PlaySong ('"Row Row Row Your Boat "', RowRow);
END.
... Dyslexic atheists don't believe in Dog.
--- Blue Wave/QBBS v2.12 [NR]
* Origin: Screen Magic -Rockwood, MI- (1:2410/225.0)